package com.jss.lanouhn.fristapp.adapters;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jss.lanouhn.fristapp.R;
import com.jss.lanouhn.fristapp.activity.SearchThingsActivity;
import com.jss.lanouhn.fristapp.modles.SearchWords;

/**
 * Created by lanouhn on 16/9/4.
 */
public class SearchWordsAdapter extends RecyclerView.Adapter<SearchWordsAdapter.WordsViewHolder>{
    private Context context;
    private SearchWords words;

    public SearchWordsAdapter(Context context, SearchWords words) {
        this.context = context;
        this.words = words;
    }

    @Override
    public WordsViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.item_search_words,null);
        WordsViewHolder holder=new WordsViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(WordsViewHolder holder, final int position) {
        holder.textView.setText(words.getData().getHot_words().get(position));
        holder.textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, SearchThingsActivity.class);
                Bundle bundle=new Bundle();
                bundle.putString("name",words.getData().getHot_words().get(position));
                intent.putExtras(bundle);
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return words.getData().getHot_words().size();
    }

    public class WordsViewHolder extends RecyclerView.ViewHolder {
    private TextView textView;
    public WordsViewHolder(View itemView) {
        super(itemView);
        textView= (TextView) itemView.findViewById(R.id.tv_search_words);
    }
}
}
